#!/bin/bash
set -e

# 输出环境变量的值
echo "PREDICTOR_LABELS: $PREDICTOR_LABELS"

# 获取tenantId
TENANT_ID=$(echo $PREDICTOR_LABELS | sed 's/.*"dc.com\/tenant.tenant-id":"\([^"]*\)".*/\1/')
echo "Tenant ID: $TENANT_ID"

# 获取projectId
PROJECT_ID=$(echo $PREDICTOR_LABELS | sed 's/.*"dc.com\/tenant.project-id":"\([^"]*\)".*/\1/')
echo "Project ID: $PROJECT_ID"

# 拼接容器内的挂载目录
LORA_DIR='/Lora'
STABLE_DIFFUSION_DIR='/Stable-diffusion'

MOUNT_LORA_DIR="/mnt/aps/tenant/$TENANT_ID/project/$PROJECT_ID/document$LORA_DIR"
echo "MOUNT_LORA_DIR: $MOUNT_LORA_DIR"

MOUNT_STABLE_DIFFUSION_DIR="/mnt/aps/tenant/$TENANT_ID/project/$PROJECT_ID/document$STABLE_DIFFUSION_DIR"
echo "MOUNT_STABLE_DIFFUSION_DIR: $MOUNT_STABLE_DIFFUSION_DIR"


# 定义软连接的目标
TARGET_LORA_DIR="/app/models/Lora"
TARGET_STABLE_DIFFUSION_DIR="/app/models/Stable-diffusion"

# 创建软链接
ln -s $MOUNT_LORA_DIR $TARGET_LORA_DIR
ln -s $MOUNT_STABLE_DIFFUSION_DIR $TARGET_STABLE_DIFFUSION_DIR

# 输出结果
echo "Created symlink: $MOUNT_LORA_DIR -> $TARGET_LORA_DIR"
echo "Created symlink: $MOUNT_STABLE_DIFFUSION_DIR -> $TARGET_STABLE_DIFFUSION_DIR"